package ru.aslanov.schedule.client.util;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Button;
import ru.aslanov.schedule.client.i18n.I18nUtil;

/**
 * Created by IntelliJ IDEA.
 * Created: Mar 9, 2010 1:49:05 PM
 *
 * @author Sergey Aslanov
 */
public class MyAsyncCallback<T> implements AsyncCallback<T> {
    protected Button button;

    public MyAsyncCallback(Button button) {
        this.button = button;
        if (button != null) button.disable();
    }

    @Override
    public void onFailure(Throwable caught) {
        if (button != null) button.enable();
        ErrorHandler.handleException(caught);
    }

    @Override
    public void onSuccess(T result) {
        if (button != null) button.enable();
        SC.say(I18nUtil.cnt().operationSuccess());
    }
}
